package com.tensquare.qa.dao;

import com.tensquare.qa.pojo.Problem;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;

/**
 * @Author:zimmor
 * @Date: 2021/3/1 14:12
 * @Description 数据接口
 * @version: 1.0.0
 */

public interface ProblemDao extends JpaRepository<Problem, String >, JpaSpecificationExecutor<Problem> {
    /**
     * 获取等待回答的问题列表
     * @param labelId
     * @param pageable
     * @return
     */
    @Query(value="SELECT * FROM tb_problem , tb_pl WHERE id = problemid AND labelid='1' AND reply='0' ORDER BY createtime  Desc", nativeQuery = true)
    public Page<Problem> waitList(String labelId, Pageable pageable);
    /**
     * 根据标签id获取最新问题列表
     * @param labelId
     * @return
     */
    @Query(value="SELECT * FROM tb_problem , tb_pl WHERE id = problemid AND labelid=? ORDER BY replytime Desc", nativeQuery=true)
    public Page<Problem> newList(String labelId, Pageable pageable);

    /**
     * 根据标签id获取最热问题列表
     * @param labelId
     * @param pageable
     * @return
     */
    @Query(value="SELECT * FROM tb_problem , tb_pl WHERE id = problemid AND labelid='1' ORDER BY reply  Desc", nativeQuery=true)
    public Page<Problem> hotList(String labelId, Pageable pageable);
}
